package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.ApArticleConfigService;
import com.heima.common.constants.WemediaConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Map;

/*
kafka消费者 ,监听broker中的消息,对app端文章配置表 ap_article_config进行更新
 */
@Slf4j
@Component
public class ArticlesDownUpListener {
    @Autowired
    private ApArticleConfigService apArticleConfigService;


    @KafkaListener(topics = WemediaConstants.WM_NEWS_UP_OR_DOWN_TOPIC)
    public void onMessage(String message) {
        if (StringUtils.isNotEmpty(message)) {
            log.info("监听到kafka中的消息...开始更新app端文章状态!");
            Map map = JSON.parseObject(message, Map.class);

            //更新文章配置表
            apArticleConfigService.updateByMap(map);
            log.info("app端文章{}配置修改成功...",map.get("articleId"));
        }
    }

}
